package com.sti.platform.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aisino.core.common.JsonPost;
import com.aisino.core.controller.BaseController;
import com.sti.platform.model.Expert;
import com.sti.platform.service.ExpertService;

@Controller
@RequestMapping("expert")
public class ExpertController extends BaseController {
	@Autowired
	private ExpertService expertService;
	
	@RequestMapping("list")
	public String expertPage(HttpServletRequest request,String params,Integer index,Integer row){
		List<Expert> list = expertService.queryList(params, index, row);
		request.setAttribute("list",list);
		return "expert/index";
	}
	
	@RequestMapping("addHtml")
	public String addHtmlPage(HttpServletRequest request){
		Map<String,Object> map = expertService.queryAddInfo();
		request.setAttribute("map", map);
		return "expert/add";
	}
	
	@RequestMapping("add")
	public @ResponseBody Map addExpert(final Expert expert){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				expertService.addExpert(expert);
			}
		});
	}
	
	@RequestMapping("editorHtml")
	public String editorHtmlPage(HttpServletRequest request,String expertId){
		Map<String,Object> map = expertService.queryAddInfo();
		Expert expert = expertService.queryExpert(expertId);
		map.put("expert",expert);
		request.setAttribute("map", map);
		return "expert/editor";
	}
	
	@RequestMapping("editor")
	public @ResponseBody Map updateExpert(final Expert expert){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				expertService.updateExpert(expert);
			}
		});
	}
	
	@RequestMapping("delect")
	public @ResponseBody Map delectExpert(final String expertId){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				expertService.delectExpert(expertId);
			}
		});
	}
	
	@RequestMapping("delects")
	public @ResponseBody Map delectExperts(final String expertIds){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				expertService.delectExperts(expertIds);
			}
		});
	}
	
	@RequestMapping("export") 
	@ResponseBody
	public void exportUser(HttpServletResponse response){
		expertService.exportExpert(response);
	}
}
